VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmMaintCommission 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   6465
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   10905
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   6465
   ScaleWidth      =   10905
   ShowInTaskbar   =   0   'False
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   255
      Left            =   0
      TabIndex        =   4
      Top             =   6210
      Width           =   10905
      _ExtentX        =   19235
      _ExtentY        =   450
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
   Begin ITGControls.ITGTab SSTab1 
      Height          =   6045
      Left            =   45
      TabIndex        =   5
      Top             =   45
      Width           =   10650
      _ExtentX        =   18785
      _ExtentY        =   10663
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   8
      Tab(0)ContCtrlCap(1)=   "txtCommission"
      Tab(0)ContCtrlCap(2)=   "txtType"
      Tab(0)ContCtrlCap(3)=   "txtName"
      Tab(0)ContCtrlCap(4)=   "txtCode"
      Tab(0)ContCtrlCap(5)=   "cmdPickCode"
      Tab(0)ContCtrlCap(6)=   "Timer1"
      Tab(0)ContCtrlCap(7)=   "ComunionFrames1"
      Tab(0)ContCtrlCap(8)=   "Label1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   0
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483630
      Begin ITGControls.ITGTextBox txtCommission 
         Height          =   285
         Left            =   4080
         TabIndex        =   8
         Top             =   840
         Width           =   2520
         _ExtentX        =   4233
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         AllCaps         =   -1  'True
         DataType        =   1
         Mandatory       =   -1  'True
         DecimalPlace    =   2
         Label           =   "Commission"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1325
         TextBoxWidth    =   1135
         Required        =   -1  'True
         LinkForeColor   =   16711680
      End
      Begin ITGControls.ITGTextBox txtType 
         Height          =   285
         Left            =   120
         TabIndex        =   7
         Top             =   840
         Width           =   3840
         _ExtentX        =   6562
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Label           =   "Customer Type"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1325
         TextBoxWidth    =   2455
         Required        =   -1  'True
         LinkForeColor   =   16711680
      End
      Begin ITGControls.ITGTextBox txtName 
         Height          =   285
         Left            =   3030
         TabIndex        =   2
         TabStop         =   0   'False
         Top             =   495
         Width           =   3810
         _ExtentX        =   6615
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Label           =   "ITGtext"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   0
         TextBoxWidth    =   3750
         Enabled         =   0   'False
      End
      Begin ITGControls.ITGTextBox txtCode 
         Height          =   285
         Left            =   120
         TabIndex        =   0
         Top             =   480
         Width           =   2520
         _ExtentX        =   4233
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Label           =   "Customer"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1325
         TextBoxWidth    =   1135
         Required        =   -1  'True
         LinkForeColor   =   16711680
      End
      Begin VB.CommandButton cmdPickCode 
         Height          =   300
         Left            =   2685
         Picture         =   "frmMaintCommission.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   1
         Top             =   480
         Width           =   315
      End
      Begin VB.Timer Timer1 
         Interval        =   300
         Left            =   8760
         Top             =   360
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   4515
         Left            =   60
         Top             =   1455
         Width           =   10515
         _ExtentX        =   18547
         _ExtentY        =   7964
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Details"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin MSDataGridLib.DataGrid dtgCC 
            Height          =   3975
            Left            =   60
            TabIndex        =   3
            Top             =   465
            Width           =   10395
            _ExtentX        =   18336
            _ExtentY        =   7011
            _Version        =   393216
            AllowUpdate     =   0   'False
            AllowArrows     =   -1  'True
            Appearance      =   0
            HeadLines       =   1
            RowHeight       =   15
            TabAction       =   2
            FormatLocked    =   -1  'True
            BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ColumnCount     =   6
            BeginProperty Column00 
               DataField       =   "cItemNo"
               Caption         =   "Product ID"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column01 
               DataField       =   "cDescription"
               Caption         =   "Description"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column02 
               DataField       =   "nSRP"
               Caption         =   "SRP"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   1
                  Format          =   "#,##0.00"
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   1
               EndProperty
            EndProperty
            BeginProperty Column03 
               DataField       =   "nCommission"
               Caption         =   "Commission %"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   1
                  Format          =   "0.00"
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   1
               EndProperty
            EndProperty
            BeginProperty Column04 
               DataField       =   "nPrice"
               Caption         =   "Price"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column05 
               DataField       =   "cBarcode"
               Caption         =   "Barcode ID"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   "#,##0.00"
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            SplitCount      =   1
            BeginProperty Split0 
               AllowRowSizing  =   0   'False
               BeginProperty Column00 
                  Button          =   -1  'True
                  ColumnWidth     =   1425.26
               EndProperty
               BeginProperty Column01 
                  ColumnWidth     =   2865.26
               EndProperty
               BeginProperty Column02 
                  Locked          =   -1  'True
               EndProperty
               BeginProperty Column03 
                  ColumnWidth     =   1154.835
               EndProperty
               BeginProperty Column04 
                  Locked          =   -1  'True
                  ColumnWidth     =   1484.787
               EndProperty
               BeginProperty Column05 
                  ColumnWidth     =   1635.024
               EndProperty
            EndProperty
         End
      End
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   2625
         Left            =   -74940
         TabIndex        =   6
         Top             =   360
         Width           =   7515
         _ExtentX        =   13256
         _ExtentY        =   4630
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   "cCode"
            Caption         =   "Customer ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cName"
            Caption         =   "Customer Name"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "%"
         Height          =   195
         Left            =   6660
         TabIndex        =   9
         Top             =   885
         Width           =   165
      End
   End
End
Attribute VB_Name = "frmMaintCommission"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables





'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

'Form mode enumeration
Enum eCommissionMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eCommissionMode

'Other declarations
Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Private Sub cmdPickCode_Click()
'    If lPickListActive Then Exit Sub
'    sFilterString = Trim(txtCode)
'    With frmITGPicker
'        .zType = QCustomer
'        .Show vbModal
'        txtCode = .zCode
'        txtName = .zName
'    End With
'    TBFindPrimary
    
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtCode)
    With frmITGPicker
        .zType = QComponents
        .Show vbModal
        txtCode = .zCode
        txtName = .zName
    End With
End Sub

Private Sub dtgCC_AfterColUpdate(ByVal ColIndex As Integer)
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount < 1 Then Exit Sub
    Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgCC.Columns(0).Value) & "'") <> "" Then
                dtgCC_ButtonClick 0
                dtgCC.Col = 3
'                dtgCC.Columns(2).Value = GetValueFrTable("nSRP", "ITEM", "cItemNo = '" & Trim(dtgCC.Columns(0).Value) & "'")
            Else
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgCC.Columns(0).Text)
                frmITGPicker.zType = QProduct
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                rsDetail!cDesc = Trim(frmITGPicker.zName) & ""
                rsDetail!nSRP = GetValueFrTable("nSRP", "ITEM", "cItemNo = '" & Trim(dtgCC.Columns(0).Value) & "'")
            End If
    End Select
End Sub

'Private Sub cboCA_Click()
'    rsDetail!cCompanyName = GetValueFrTable("cCompanyName", "COMPANY", "cCompanyID = '" & Trim(cboCA) & "'", True)
'    rsDetail!cCompanyID = cboCA
'End Sub
'
'Private Sub cboCA_KeyDown(KeyCode As Integer, Shift As Integer)
'    If KeyCode = 13 Then
'        If dtgCC.Col = 0 Then
'            rsDetail!cCompanyID = cboCA
'            cboCA.Visible = False
'            TBNewLine
'        End If
'    ElseIf KeyCode = vbKeyEscape Then
'        cboCA.Visible = False
'    End If
'End Sub
'
'Private Sub cboCA_LostFocus()
'    cboCA.Visible = False
'End Sub

Private Sub dtgCC_ButtonClick(ByVal ColIndex As Integer)
On Error Resume Next
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount < 1 Then Exit Sub
    Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgCC.Columns(0).Value) & "'") = "" Then
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgCC.Columns(0).Text)
                frmITGPicker.zType = QProduct
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                dtgCC.Columns(0).Value = rsDetail!cItemNo
                rsDetail!cDescription = Trim(frmITGPicker.zName) & ""
                rsDetail!nSRP = GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(dtgCC.Columns(0).Value) & "'")
'                If (Trim(frmITGPicker.zName) & "") <> "" Then
'                    dtgSO.Col = 3
'                    GetInitialItemValues
'                    If rsHeader!cType <> "Consignment" And rsHeader!cType <> "For Sales-Con" Then
'                        rsDetail!cPricing = GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True)
'                        GetRWMPrice
'                    Else
'                        rsDetail!cPricing = "Regular"
'                        GetConPrice
'                    End If
'
'                    dtgSO.Columns(3).Value = rsDetail!cUnit
'                End If
'
'                'mon
'                If GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(dtgSO.Columns(1).Value) & "'") = "Labor" Then
'                dtgSO.Columns(10).Value = "Labor"
                End If
        Case Else
                SendKeys "{Tab}"
    End Select
End Sub

'Set the datagrid as active control
Private Sub dtgCC_Click()
    If Mode = AddNewEdit Then dtgName = dtgCC.Name
End Sub

Private Sub dtgCC_Error(ByVal DataError As Integer, Response As Integer)
    If DataError = 7007 Then
        MsgBox "Type mismatch", vbExclamation, msgTtl
    ElseIf DataError = 13 Then
        MsgBox "Type mismatch", vbExclamation, msgTtl
    End If
    Response = 0
End Sub

Private Sub dtgCC_GotFocus()
    dtgName = dtgCC.Name
End Sub

Private Sub dtgCC_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgCC_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgCC.Col
            Case 0
                If dtgCC.Columns(0).Value = "" Then
                    dtgCC_ButtonClick 0
                End If
                    SendKeys "{Tab}"
                    SendKeys "{Tab}"
                    SendKeys "{Tab}"
                
            Case 3
'                If Not cboCA.Visible Then dtgCC_ButtonClick 0
                dtgCC.Columns(4).Value = CDbl(dtgCC.Columns(2).Value) - (CDbl(dtgCC.Columns(2).Value) * (CDbl(dtgCC.Columns(3).Value) / 100))
                SendKeys "{Tab}"
                SendKeys "{Tab}"
            Case 5
                TBNewLine
                dtgCC.LeftCol = 0
        Case Else
                SendKeys "{Tab}"
        End Select
    End If
End Sub

'Right click menu popup
Private Sub dtgCC_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgCC.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()

    Set FrmName = Me
    FormSetup

    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'MF31'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    

    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    Mode = Find
    txtCode.Locked = False
    cmdPickCode.Enabled = True
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If

    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    
    
    
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    
    Set frmSecCompanyAccess = Nothing

    lCloseWindow = True
    
    'oForm(Me.Tag).Mode = 1
    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()

    '**********

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , lACEdit, , , , , , , , True, True, , True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True
    
    If Not MandatoryOK Then Exit Sub
    
    OKUpdate = False
    cn.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    cn.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , lACEdit, , , , , , , , True, True, , True
    Mode = Normal
    
    MsgBox "Record/s successfully saved.", vbInformation, msgTtl
    sbRS.Panels(2) = ""
    
    'Audit trail
    UpdateLogFile "Commission - Consignee", Trim(txtCode), IIf(lBoolean, "Inserted", "Updated")

ErrHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, msgTtl
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , lACEdit, , , , , , , , True, True, , True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, msgTtl
        cn.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtCode.Locked = True
    txtType.Locked = True
    dtgCC.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtCode.Locked = True
    txtType.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()

        'Find
        If Mode = Find Then
            
            FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
            Set rsHeader = Nothing
            Set rsDetail = Nothing
            Set rsHeader = New ADODB.Recordset
            Set rsDetail = New ADODB.Recordset

            If Trim(txtCode) = "" Then
                OpenRecordset rsDetail, "*", "COMMISSION_CUSTOMER", , True
                OpenRecordset rsHeader, "*", "CLIENT_CUSTOMER", , True
            Else
                OpenRecordset rsDetail, "*", "COMMISSION_CUSTOMER", "WHERE cCode LIKE '" & Trim(txtCode) & "%'"
                OpenRecordset rsHeader, "*", "CLIENT_CUSTOMER", "WHERE cCode LIKE '" & Trim(txtCode) & "%'"
            End If

            Set FrmName = Me
            FormLocking True

            If rsHeader.RecordCount = 0 Then
                FormWaitHide
                MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
                rsHeader.Close
                rsDetail.Close
                BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True, , , True
                txtCode.Locked = False
                txtCode.SetFocus
                Exit Sub
            End If

            SetDataSource
            SetDataField

            txtCode.BackColor = &HE0FFFF
            
            Mode = Normal

            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , lACEdit, , , , , , , , True, True, , True

            FormWaitHide
    Else
    RSZero
    Mode = Find
    cmdPickCode.Enabled = True
    End If
End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgCC.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    
    If dtgName = "dtgCC" Then
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cCode = Trim(rsHeader!cCode)
        dtgCC.Col = 0
        dtgCC.Columns(0).Value = ""
        GetChild
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
        dtgCC.SetFocus
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgCC.Name Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgCC.Bookmark
        GetChild
        dtgCC.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Cancel current record
Public Sub TBCancelRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Print
Public Sub TBPrintRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgCC.DataSource = rsDetail
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtCode.DataField = !cCode
        txtCommission.DataField = !nCommission
        txtType.DataField = !cCustomerType
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtCode.Locked = True
        Else
            txtCode.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtCode.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgCC.Refresh
    End If

ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
    
    If Mode <> Find Then Exit Sub
    If txtCode.BackColor = &HE0FFFF Then
        txtCode.BackColor = &HE0E0E0
        Exit Sub
    End If
    If txtCode.BackColor <> &HE0FFFF Then
        txtCode.BackColor = &HE0FFFF
        Exit Sub
    End If
End Sub

Private Sub txtCode_Change()
    txtName = ""
'    sSQL = "SELECT (LastName + ', ' + LastName + ' ' + MI + '.') AS Name FROM SEC_USER WHERE UserID = '" & Trim(txtUserID) & "'"
'    sSQL = "SELEC"
'    Set rs = New Recordset
'    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
'    If rs.RecordCount <> 0 Then
'        txtName = Trim(rs!Name)
'    Else
'        txtName = ""
'    End If
'    Set rs = Nothing
    txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean

    MandatoryOK = True

    GetChild
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else
                rsDetail.MoveNext
            End If
        Else
            rsDetail.MoveNext
        End If
    Loop

    GetChild

End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cCode = '" & Trim(rsHeader!cCode) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    
    Set dtgCC.DataSource = Nothing
    dtgCC.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True, , , True
    
    txtCode.Locked = False
    txtCode.SetFocus
    
    Mode = Find
    
End Sub




